home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / util / PageSize.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  5KB  |  120 lines

  1. /*    $Header: /usr/people/sam/fax/util/RCS/PageSize.h,v 1.9 1994/02/28 14:23:52 sam Rel $ */
  2. /*
  3.  * Copyright (c) 1993, 1994 Sam Leffler
  4.  * Copyright (c) 1993, 1994 Silicon Graphics, Inc.
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and 
  7.  * its documentation for any purpose is hereby granted without fee, provided
  8.  * that (i) the above copyright notices and this permission notice appear in
  9.  * all copies of the software and related documentation, and (ii) the names of
  10.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  11.  * publicity relating to the software without the specific, prior written
  12.  * permission of Sam Leffler and Silicon Graphics.
  13.  * 
  14.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  15.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  16.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  17.  * 
  18.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  19.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  20.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  22.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  23.  * OF THIS SOFTWARE.
  24.  */
  25. #ifndef _PAGESIZE_
  26. #define    _PAGESIZE_
  27. /*
  28.  * Page size information.
  29.  */
  30. #if defined(c_plusplus) || defined(__cplusplus)
  31. #include "Str.h"
  32.  
  33. class PageInfoArray;
  34.  
  35. typedef unsigned int BMU;    // ISO basic measurement unit
  36. struct PageInfo {
  37.     const char* name;    // page size name
  38.     const char* abbr;    // abbreviated name
  39.     BMU    w, h;        // nominal page width & height
  40.     BMU    grw, grh;    // guaranteed reproducible width & height
  41.     BMU    top;        // top margin for grh
  42.     BMU    left;        // bottom margin for grw
  43. };
  44.  
  45. class PageSizeInfo {
  46. private:
  47.     const PageInfo* info;
  48.  
  49.     friend class PageSizeInfoIter;
  50.  
  51.     PageSizeInfo(const PageInfo&);
  52.  
  53.     static PageInfoArray* pageInfo;
  54.  
  55.     static const PageInfo* getPageInfoByName(const char* name);
  56.     static PageInfoArray* readPageInfoFile();
  57.     static fxBool skipws(char*& cp,
  58.         const char* file, const char* item, u_int lineno);
  59.  
  60.     static float toMM(BMU v)        { return (v/1200.)*25.4; }
  61.     static BMU fromMM(float v)        { return BMU((v/25.4)*1200); }
  62. public:
  63.     PageSizeInfo();
  64.     ~PageSizeInfo();
  65.  
  66.     static PageSizeInfo* getPageSizeByName(const char*);
  67.     static PageSizeInfo* getPageSizeBySize(float w, float h);
  68.  
  69.     const char* name() const;        // fully qualified page size name
  70.     const char* abbrev() const;        // abbreviated name
  71.     float width() const;        // nominal page width (mm)
  72.     float height() const;        // nominal page height (mm)
  73.     float guarWidth() const;        // guaranteed reproducible width (mm)
  74.     float guarHeight() const;        // guaranteed reproducible height (mm)
  75.     float topMargin() const;        // top margin for GRA (mm)
  76.     float leftMargin() const;        // left margin for GRA (mm)
  77. };
  78. inline const char* PageSizeInfo::name() const    { return info->name; }
  79. inline const char* PageSizeInfo::abbrev() const    { return info->abbr; }
  80. inline float PageSizeInfo::width() const    { return toMM(info->w); }
  81. inline float PageSizeInfo::height() const    { return toMM(info->h); }
  82. inline float PageSizeInfo::guarHeight() const    { return toMM(info->grh); }
  83. inline float PageSizeInfo::guarWidth() const    { return toMM(info->grw); }
  84. inline float PageSizeInfo::topMargin() const    { return toMM(info->top); }
  85. inline float PageSizeInfo::leftMargin() const    { return toMM(info->left); }
  86.  
  87. /*
  88.  * For iterating over the available page sizes.
  89.  */
  90. class PageSizeInfoIter {
  91. private:
  92.     PageSizeInfo pi;
  93.     u_int    i;
  94. public:
  95.     PageSizeInfoIter();
  96.     ~PageSizeInfoIter();
  97.     void operator++();
  98.     void operator++(int);
  99.     operator const PageSizeInfo&();
  100.     fxBool notDone();
  101. };
  102. #else
  103. /*
  104.  * C interface to get at information...
  105.  */
  106. struct pageSizeInfo;            /* opaque handle */
  107. extern struct pageSizeInfo* getPageSize(const char* name);
  108. extern struct pageSizeInfo* closestPageSize(float w, float h);
  109. extern void delPageSize(struct pageSizeInfo*);
  110. extern const char* getPageName(const struct pageSizeInfo*);
  111. extern const char* getPageAbbrev(const struct pageSizeInfo*);
  112. extern float getPageWidth(const struct pageSizeInfo*);
  113. extern float getPageHeight(const struct pageSizeInfo*);
  114. extern float getPageGuarHeight(const struct pageSizeInfo*);
  115. extern float getPageGuarWidth(const struct pageSizeInfo*);
  116. extern float getPageTopMargin(const struct pageSizeInfo*);
  117. extern float getPageLeftMargin(const struct pageSizeInfo*);
  118. #endif
  119. #endif /* _PAGESIZE_ */
  120.